package com.splic.common.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

/**
 * 验证码验证码类型
 * Created by Loubing
 * Date 2020/7/1 17:25
 */
public enum EmailCodeTypeEnum {

    REG(1,"reg", "注册", "ST_1ckmr57etsg"), // 注册手机验证
    UP_PASS(2,"up_pass", "重置密码", "ST_4wf44l6glg"),// 修改密码
    BUY_VIP(3,"buy_vip", "购买会员", "ST_7ngo4g1r05"),// 绑定支付宝账号
    LOGIN(4,"login","登录", "ST_9i7o1fu4ls"),// 手机验证码登录
    APPLY_ACCOUNT_INFO(8,"apply_account_info", "提取资料", "ST_ajawxiqii5"),//申请账号资料信息(steam,orgin)
    EMAIL_VERIFIC(10,"email", "邮箱验证", "ST_1ckmr57etsg"), // 注册手机验证
    MOBILE_VERIFIC(11,"mobile", "手机号验证", "ST_1ckmr57etsg"), // 注册手机验证
    FEEDBACK(20,"feedback", "用户反馈", "ST_1ckmr57etsg"), // 注册手机验证
    SUBSCRIBE(21,"subscribe", "用户订阅", "ST_1ckmr57etsg"), // 注册手机验证
    ;



    private Integer val;
    private String code;
    private String desc;
    private String smsTemplateId;
    private static Map<String, String> emailCodeTypes = new TreeMap();

    EmailCodeTypeEnum(Integer val, String code, String desc, String smsTemplateId) {
        this.val = val;
        this.code = code;
        this.desc = desc;
        this.smsTemplateId = smsTemplateId;
    }

    public String getDesc() {
        return desc;
    }

    public String getSmsTemplateId() {
        return smsTemplateId;
    }

    public Integer getVal() {
        return val;
    }

    public String getValString() {
        return val.toString();
    }

    public String getCode() {
        return code;
    }
    static {
        emailCodeTypes = Arrays.stream(values()).collect(Collectors.toMap(EmailCodeTypeEnum::getValString, EmailCodeTypeEnum::getCode));
    }

    public static EmailCodeTypeEnum getCode(String code) {
        EmailCodeTypeEnum[] enums = values();
        for (EmailCodeTypeEnum tempEnum : enums) {
            if (tempEnum.code.equals(code)) {
                return tempEnum;
            }
        }
        return null;
    }


    public static EmailCodeTypeEnum get(Integer val) {
        if (val == null) {
            return null;
        }

        for (EmailCodeTypeEnum value : EmailCodeTypeEnum.values()) {
            if (value.val.intValue() == val) {
                return value;
            }
        }

        return null;
    }

    public static Map<String, String> getEmailCodeTypes() {
        return emailCodeTypes;
    }
}
